// Object.getOwnPropertyDescriptor( object, propertyName )
// 作用: 从指定对象(object)中获取其自有属性(propertyName)的描述符(descriptor)
// 返回: 返回指定对象指定自有属性的描述符(descriptor)

// 用 "对象字面量" 创建对象(实际是个实例)
const x = {
    id: 1001,
    name: '得芳',
    age: 18
}

console.log( x );

const idDescriptor = Object.getOwnPropertyDescriptor( x, 'id' );
console.log( idDescriptor );

const nameDescriptor = Object.getOwnPropertyDescriptor( x, 'name' );
console.log( nameDescriptor );

const ageDescriptor = Object.getOwnPropertyDescriptor( x, 'age' );
console.log( ageDescriptor );

const descriptor = {
    enumerable: false,
    writable: false,
    configurable: false,
}

// 为已有属性修改描述符
// 修改已有属性的描述符时，描述符中有那些特征就为属性修改那些特征
Object.defineProperty(x, 'id', descriptor);
Object.defineProperty(x, 'name', descriptor);
Object.defineProperty(x, 'age', descriptor);

console.log( x );
console.log( x.id, x.name, x.age );

x.id = 2002;
x.name = '小芳';
x.age = 22;

console.log( x.id, x.name, x.age );

delete x.id;
delete x.name;
delete x.age;

console.log( x.id, x.name, x.age );